package behavior.interpreter;

import java.math.BigDecimal;

public class TerminalExpression extends AbstractExpression{

    private String expression;
    public TerminalExpression(String _expression){
        expression = _expression;
    }

    @Override
    public BigDecimal interpreter(ParseContext context) {
        //测试是否是数字格式
        try{
            return new BigDecimal(expression);
        }catch(Exception e){}

        //测试是否可以从context获取
        if(context.getValue(expression) != null) return context.getValue(expression);
        throw new UnsupportedOperationException("expression not found in context: ["+expression+"]");
    }
}
